/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ihmprojet.view;

import ihmprojet.core.Context;
import java.awt.FlowLayout;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author thomas
 */
public class ConteneurMinimapPanel extends javax.swing.JPanel {

    private MiniMap mapCur;
    private Context curContext;
    private Set<MiniMap> mappy = new HashSet<MiniMap>();
    private FenetrePrincipale fenp;

    /**
     * Creates new form ConteneurMinimapPanel
     */
    public ConteneurMinimapPanel() {
        initComponents();
    }

    public void afficherMap(String idSelect) {
        for (MiniMap m : mappy) {
            if (m.getId().equals(idSelect)) {
                mapCur.setVisible(false);
                mapCur = m;
                mapCur.setVisible(true);
            }
        }
    }

    public void addMap(Context currentContext, String id) {
        MiniMap mm = new MiniMap(currentContext, id, fenp);
        mappy.add(mm);
        curContext = currentContext;
        this.add(mm);
        mm.setVisible(true);
        afficherMap(id);

    }

    ConteneurMinimapPanel(Context currentContext, String id, FenetrePrincipale fp) {
        initComponents();
        this.curContext = currentContext;
        fenp = fp;
        this.mapCur = new MiniMap(currentContext, id, fp);
        this.setLayout(new FlowLayout());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setPreferredSize(new java.awt.Dimension(150, 150));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    void fireChangement() {
        mapCur.fireChangement();
    }

    void stateChanged(String id) {
       afficherMap(id);
    }
}
